package cn.com.yto56.sample.ztree.server.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.com.yto56.sample.ztree.server.dao.ZtreeDAO;
import cn.com.yto56.sample.ztree.util.beans.SuperBean;

public class ZtreeDAOImpl extends SqlMapClientDaoSupport implements ZtreeDAO {

	@Override
	public List<SuperBean> querySql(Map<String , Object> param , Class beanType) throws Exception {
		
		List<Map<String , Object>> resultList = getSqlMapClientTemplate().queryForList("querySql", param);
		List<SuperBean> beanList = null;
		
		if(resultList != null && resultList.size() > 0) {
			beanList = new ArrayList<SuperBean>();
			SuperBean bean = (SuperBean) Class.forName(beanType.getName()).newInstance();

			for(Map<String , Object> result : resultList) {
				beanList.add(bean.getMapToBean(result, beanType));
			}
			
		}
		
		return beanList;
	}

}
